using System;
using System.Data;
using System.Windows.Forms;
using HSHLogicLayer;
using HSHLogicLayer.DataWS;

namespace TaskVision
{
	public class FindPeopleThread
	{
		private DSPeople tblFindPeople;
		private string m_Idnumber;
		private string m_PartialName;
 
		public delegate void FindFinishedEventHandler(FindPeopleThread ThisThread);
		public event FindFinishedEventHandler Finished;
 
		public FindPeopleThread(string Idnumber, string PartialName)
		{
			m_Idnumber = Idnumber;
			m_PartialName = PartialName;
		}
 
		public void Find()
		{
			FindPeopleToTable();
			if (Finished != null)
				Finished(this);
 
		}
 
		/// <summary>
		/// return DataTable of matches People
		/// </summary>
		private void FindPeopleToTable()
		{
            tblFindPeople = (DSPeople)DataLayerSingleton.Instance().FindPeople(m_Idnumber,m_PartialName).DataSet;
		}
 
		public DSPeople DataSource
		{
			get   {return this.tblFindPeople;}
		}

        public int IdNumber
        {
            get
            {
                return (tblFindPeople.People.Rows.Count == 1) ? Convert.ToInt32(tblFindPeople.People.Rows[0]["IsraelID"]) : Convert.ToInt32(m_Idnumber);
            }
        }
	}
}
